package com.heqiang.spring;

import com.heqiang.spring.bean.PropertyValue;
import com.heqiang.spring.bean.PropertyValues;
import com.heqiang.spring.config.BeanDefinition;
import com.heqiang.spring.config.BeanReference;
import com.heqiang.spring.factory.DefaultListableBeanFactory;
import com.heqiang.spring.service.TestDao;
import com.heqiang.spring.service.TestService;

/**
 * 学习链接
 * https://mp.weixin.qq.com/s/EKoMDpa4q8TMikRM2wBIzw
 */
public class TestMain {


    public static void main(String[] args) {
        //初始化beanFactory
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        //dao注册
        beanFactory.registerBeanDefinition("testDao",new BeanDefinition(TestDao.class));

        //service设置属性
        PropertyValues propertyValues = new PropertyValues();
        propertyValues.addProperValue(new PropertyValue("uId","1004"));
        propertyValues.addProperValue(new PropertyValue("testDao",new BeanReference("testDao")));

        //service注入bean
        BeanDefinition beanDefinition = new BeanDefinition(TestService.class,propertyValues);
        beanFactory.registerBeanDefinition("testService",beanDefinition);

        //service获取Bean
        TestService testService = (TestService) beanFactory.getBean("testService");
        testService.queryInfo();
    }


}
